package br.com.news.database.services;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import br.com.news.database.daos.interfaces.IRespostaEnqueteDao;
import br.com.news.database.entities.RespostaEnqueteEntity;
import br.com.news.database.exception.DataBaseException;
import br.com.news.database.utils.GenericService;
import br.com.news.database.utils.interfaces.IGenericDao;
import br.com.news.utils.database.beans.RespostaEnqueteBean;
import br.com.news.utils.database.exception.DataBaseServiceException;
import br.com.news.utils.database.interfaces.IRespostaEnqueteServiceDb;

@Named
public class RespostaEnqueteServiceDb extends GenericService<RespostaEnqueteBean, RespostaEnqueteEntity, Long> implements IRespostaEnqueteServiceDb{

	@Inject
	private IRespostaEnqueteDao respostaEnqueteDao;

	@Override
	protected IGenericDao<RespostaEnqueteEntity, Long> getConcreteDao() {
		return this.respostaEnqueteDao;
	}

	@Override
	public void save(RespostaEnqueteBean respostaEnquete) throws DataBaseServiceException {
		try {
			respostaEnqueteDao.save(parserBean(respostaEnquete));
		} catch (DataBaseException e) {
			throw new DataBaseServiceException("Erro ao tentar salvar a entidade",e);
		}
	}

	@Override
	public List<RespostaEnqueteBean> resultVoteXml(long idEnquete) throws DataBaseServiceException {
		try {
			return parserEntity(this.respostaEnqueteDao.resultVoteXml(idEnquete));
		} catch (DataBaseException e) {
			throw new DataBaseServiceException("Erro ao tentar salvar a entidade",e);
		}
	}

}
